#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int jump(vector<int>& nums) {
        int n = nums.size();
        if (n == 1)
        {
            return 0;
        }
        int ans = 0;
        int right = min(nums[0], n - 1);
        int canMaxRight = nums[0];
        for (int i = 0;i < n;i++)
        {
            canMaxRight = max(canMaxRight, i + nums[i]);
            if (i == right)
            {

                ans++;
                right = min(canMaxRight, n - 1);
            }
        }
        return ans;
    }
};